<?php

$lid = intval($_GET['lid']);
if (empty($lid)) {
    header('Location: '.XOOPS_URL.'/');
    exit();
}
$cid = intval($_GET['cid']);
if ( $xoopsModuleConfig['check_host'] ) {
    $goodhost      = 0;
    $referer       = parse_url(xoops_getenv('HTTP_REFERER'));
    $referer_host  = $referer['host'];
    foreach ( $xoopsModuleConfig['referers'] as $ref ) {
        if ( !empty($ref) && preg_match("/".$ref."/i", $referer_host) ) {
            $goodhost = "1";
            break;
        }
    }
    if (!$goodhost) {
        redirect_header(XOOPSMYDOWNLOADURL. "/singlefile.php?cid=$cid&amp;lid=$lid", 20, _MD_MYDOWNLOADS_NOPERMISETOLINK);
        exit();
    }
}
$sql = sprintf("UPDATE %s SET hits = hits+1 WHERE lid = %u AND status > 0", $xoopsDB->prefix($mydirname."_downloads"), $lid);
$xoopsDB->queryF($sql);
$result = $xoopsDB->query("SELECT url FROM ".$xoopsDB->prefix($mydirname."_downloads")." WHERE lid=$lid AND status>0");
list($url) = $xoopsDB->fetchRow($result);
if (empty($url)) {
    header('Location: '.XOOPS_URL.'/');
    exit();
}
if (!preg_match("/^ed2k*:\/\//i", $url)) {
    Header("Location: $url");
}
$url = htmlspecialchars(preg_replace( '/javascript:/si' , 'java script:', $url ), ENT_QUOTES);
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=".$url."\"></meta></head><body></body></html>";
exit();

?>